

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>easylogger &mdash; easylogger v0.1 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="easylogger v0.1 documentation" href="../index.html" />
    <link rel="up" title="Module code" href="index.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../index.html">easylogger v0.1 documentation</a> &raquo;</li>
          <li><a href="index.html" accesskey="U">Module code</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <h1>Source code for easylogger</h1><div class="highlight"><pre>
<span class="c">#!/usr/bin/env python</span>
<span class="c"># -*- coding: utf-8 -*-</span>
<span class="c"># created at 27.03.2011</span>

<span class="c"># This software is distributed under the BSD license.</span>
<span class="c"># http://www.opensource.org/licenses/bsd-license.php </span>
<span class="c"># Copyright © 2011, Oleg Churkin</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">Here is a wrapper for standard :mod:`logging` module, which provides some new</span>
<span class="sd">logging facilities and allows accessing them in more Pythonic way.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">__version__</span> <span class="o">=</span> <span class="s">&quot;0.1&quot;</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">inspect</span>

<span class="c"># Python version check: 2.6 and higher is required.</span>
<span class="k">if</span> <span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">2</span> <span class="ow">or</span> 
    <span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="mi">2</span> <span class="ow">and</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">&lt;</span> <span class="mi">6</span><span class="p">)):</span>
    <span class="k">raise</span> <span class="ne">ImportError</span><span class="p">(</span><span class="s">&quot;Minimum Python version 2.6 is required.&quot;</span>
                      <span class="s">&quot; Your current Python version is&quot;</span>
                      <span class="s">&quot; </span><span class="si">%s</span><span class="s">.</span><span class="si">%s</span><span class="s">.&quot;</span> <span class="o">%</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="p">[:</span><span class="mi">2</span><span class="p">])</span>

<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">functools</span>
<span class="kn">from</span> <span class="nn">logging</span> <span class="kn">import</span> <span class="p">(</span><span class="n">INFO</span><span class="p">,</span> <span class="n">DEBUG</span><span class="p">,</span> <span class="n">CRITICAL</span><span class="p">,</span> <span class="n">WARN</span><span class="p">,</span>   <span class="c">#IGNORE:W0611 @UnusedImport</span>
                     <span class="n">WARNING</span><span class="p">,</span> <span class="n">ERROR</span><span class="p">,</span> <span class="n">FATAL</span><span class="p">,</span> <span class="n">NOTSET</span><span class="p">)</span> <span class="c">#@UnusedImport</span>


<span class="n">__all__</span> <span class="o">=</span> <span class="p">[</span><span class="s">&quot;INFO&quot;</span><span class="p">,</span> <span class="s">&quot;DEBUG&quot;</span><span class="p">,</span> <span class="s">&quot;CRITICAL&quot;</span><span class="p">,</span> <span class="s">&quot;WARN&quot;</span><span class="p">,</span> <span class="s">&quot;WARNING&quot;</span><span class="p">,</span> <span class="s">&quot;ERROR&quot;</span><span class="p">,</span> <span class="s">&quot;FATAL&quot;</span><span class="p">,</span>
           <span class="s">&quot;NOTSET&quot;</span><span class="p">,</span> <span class="s">&quot;DOC&quot;</span><span class="p">,</span> <span class="s">&quot;STDOUT&quot;</span><span class="p">,</span> <span class="s">&quot;STDERR&quot;</span><span class="p">,</span> <span class="s">&quot;log&quot;</span><span class="p">,</span> <span class="s">&quot;info&quot;</span><span class="p">,</span> <span class="s">&quot;debug&quot;</span><span class="p">,</span> <span class="s">&quot;error&quot;</span><span class="p">,</span>
           <span class="s">&quot;warning&quot;</span><span class="p">,</span> <span class="s">&quot;warn&quot;</span><span class="p">,</span><span class="s">&quot;exception&quot;</span><span class="p">,</span> <span class="s">&quot;critical&quot;</span><span class="p">,</span> <span class="s">&quot;compose_handler&quot;</span><span class="p">,</span>
           <span class="s">&quot;get_logger&quot;</span><span class="p">,</span> <span class="s">&quot;get_default_logger&quot;</span><span class="p">,</span> <span class="s">&quot;LoggingOptions&quot;</span><span class="p">,</span> <span class="s">&quot;LoggerAdapter&quot;</span><span class="p">]</span>

<span class="c"># logging level priorities:</span>
<span class="c"># NOTSET &lt; DEBUG &lt; DOC &lt; INFO &lt; STDOUT &lt; WARNING (WARN) &lt; ERROR &lt; STDERR &lt; CRITICAL (FATAL)</span>

<span class="n">DOC</span> <span class="o">=</span> <span class="mi">15</span>
<span class="n">logging</span><span class="o">.</span><span class="n">addLevelName</span><span class="p">(</span><span class="n">DOC</span><span class="p">,</span> <span class="s">&quot;DOC&quot;</span><span class="p">)</span>
<span class="n">STDOUT</span> <span class="o">=</span> <span class="mi">25</span>
<span class="n">logging</span><span class="o">.</span><span class="n">addLevelName</span><span class="p">(</span><span class="n">STDOUT</span><span class="p">,</span> <span class="s">&quot;STDOUT&quot;</span><span class="p">)</span>
<span class="n">STDERR</span> <span class="o">=</span> <span class="mi">45</span>
<span class="n">logging</span><span class="o">.</span><span class="n">addLevelName</span><span class="p">(</span><span class="n">STDERR</span><span class="p">,</span> <span class="s">&quot;STDERR&quot;</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">Defaults</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <span class="c">#IGNORE:R0903</span>
    <span class="sd">&quot;&quot;&quot;Namespace with default values.&quot;&quot;&quot;</span>
    
    <span class="n">GLOBAL_LOGGING_LEVEL</span> <span class="o">=</span> <span class="n">DEBUG</span>
    <span class="n">STREAM_MESSAGE_FORMAT</span> <span class="o">=</span> <span class="p">(</span><span class="s">&quot;</span><span class="si">%(asctime)s</span><span class="s"> [</span><span class="si">%(levelname)-8s</span><span class="s">] </span><span class="si">%(message)s</span><span class="s">&quot;</span><span class="p">,</span> <span class="s">&quot;%H:%M:%S&quot;</span><span class="p">)</span>
    <span class="n">FILE_MESSAGE_FORMAT</span> <span class="o">=</span> <span class="s">&quot;</span><span class="si">%(asctime)s</span><span class="s"> [</span><span class="si">%(levelname)-8s</span><span class="s">] </span><span class="si">%(message)s</span><span class="s">&quot;</span>


<div class="viewcode-block" id="LoggingOptions"><a class="viewcode-back" href="../index.html#easylogger.LoggingOptions">[docs]</a><span class="k">class</span> <span class="nc">LoggingOptions</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <span class="c">#IGNORE:R0903</span>
    <span class="sd">&quot;&quot;&quot;This structure contains different logging options.</span>
<span class="sd">    </span>
<span class="sd">    Available options:</span>
<span class="sd">        * **indent_size** - specifies number of spaces to be inserted before</span>
<span class="sd">            &#39;%(message)s&#39; parameter, see logging.Formatter for more details;</span>
<span class="sd">        * **enable_new_style** - if ``True`` log&#39;s methods will join all provided</span>
<span class="sd">            positional arguments with space as delimiter, e.g.:</span>
<span class="sd">                &gt;&gt;&gt; log.info(&quot;I&quot;, &quot;am&quot;, &quot;fine.&quot;)</span>
<span class="sd">                I am fine.</span>
<span class="sd">        * **new_style_delimiter** - delimiter between message parts when new</span>
<span class="sd">            message style is enabled, space by default;</span>
<span class="sd">        * **enable_decorator_mode** - if ``True`` log&#39;s methods will produce necessary</span>
<span class="sd">            messages when used as decorators, otherwise no output will be produced;</span>
<span class="sd">        * **enable_doc_processing** - if ``True`` all doc strings will be logged by log</span>
<span class="sd">            or its method used as decorators;</span>
<span class="sd">        * **doc_processing_prefix** - if specified, only doc strings begins with</span>
<span class="sd">            this character(s) will be logged. Character(s) will be stripped</span>
<span class="sd">            from logged message;</span>
<span class="sd">        * **doc_processing_level** - logging level for logged doc strings, by default</span>
<span class="sd">            it&#39;s :const:`DOC`;</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">indent</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">enable_new_style</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="n">new_style_delimiter</span> <span class="o">=</span> <span class="s">&quot; &quot;</span>
    <span class="n">enable_decorator_mode</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="n">enable_doc_processing</span> <span class="o">=</span> <span class="bp">True</span>
    <span class="n">doc_processing_prefix</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="n">doc_processing_level</span> <span class="o">=</span> <span class="n">DOC</span>

</div>
<div class="viewcode-block" id="compose_handler"><a class="viewcode-back" href="../index.html#easylogger.compose_handler">[docs]</a><span class="k">def</span> <span class="nf">compose_handler</span><span class="p">(</span><span class="n">handler</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">format_tuple</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">filter_name</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Help to compose final handler.</span>
<span class="sd">    </span>
<span class="sd">    :param handler: any handler object from logging and logging.handlers;</span>
<span class="sd">    :param level: logging level (``INFO``, ``DEBUG`` and so on);</span>
<span class="sd">    :param format_tuple: message format tuple (fmt, datefmt), see :class:`logging.Formatter`.</span>
<span class="sd">        Only if string is provided, ``datefmt`` will be passed as None;</span>
<span class="sd">    :param filter_name: filter name, see :class:`logging.Filter`;</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="k">if</span> <span class="n">level</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
    
    <span class="k">if</span> <span class="n">format_tuple</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">format_tuple</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">):</span>
            <span class="n">format_tuple</span> <span class="o">=</span> <span class="p">(</span><span class="n">format_tuple</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="n">fmt</span><span class="o">=</span><span class="n">format_tuple</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span>
                                               <span class="n">datefmt</span><span class="o">=</span><span class="n">format_tuple</span><span class="p">[</span><span class="mi">1</span><span class="p">]))</span>
    
    <span class="k">if</span> <span class="n">filter_name</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">handler</span><span class="o">.</span><span class="n">addFilter</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">Filter</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">filter_name</span><span class="p">))</span>
    
    <span class="k">return</span> <span class="n">handler</span>
    
</div>
<div class="viewcode-block" id="get_logger"><a class="viewcode-back" href="../index.html#easylogger.get_logger">[docs]</a><span class="k">def</span> <span class="nf">get_logger</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">handlers</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">extra</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Return basic logger object.</span>
<span class="sd">        </span>
<span class="sd">    :param name: logger&#39;s name;</span>
<span class="sd">    :param level: logging level, if not specified and some handlers are provided,</span>
<span class="sd">        minimum of all their levels will be taken. If final value is ``NOTSET``,</span>
<span class="sd">        then :const:`Defaults.GLOBAL_LOGGING_LEVEL` will be used;</span>
<span class="sd">    :param handlers: list of handlers for created logger to attach,</span>
<span class="sd">        if value is not iterable, it will be put in</span>
<span class="sd">        a list automatically;</span>
<span class="sd">    :param options: :class:`LoggingOptions` object;</span>
<span class="sd">    :param extra: extra arguments for underlying logging functionality, see </span>
<span class="sd">        documentation for :mod:`logging`;</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">level</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">level</span> <span class="o">=</span> <span class="nb">min</span><span class="p">([</span><span class="n">_</span><span class="o">.</span><span class="n">level</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="p">(</span><span class="n">handlers</span> <span class="ow">or</span> <span class="p">[])]</span> <span class="ow">or</span> <span class="p">[</span><span class="n">NOTSET</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">level</span> <span class="o">==</span> <span class="n">NOTSET</span><span class="p">:</span>
            <span class="n">level</span> <span class="o">=</span> <span class="n">Defaults</span><span class="o">.</span><span class="n">GLOBAL_LOGGING_LEVEL</span>
        
    <span class="k">if</span> <span class="n">name</span><span class="p">:</span>
        <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>
        <span class="n">logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">logger</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">RootLogger</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
    
    <span class="k">if</span> <span class="n">handlers</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">handlers</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="n">handlers</span> <span class="o">=</span> <span class="p">[</span><span class="n">handlers</span><span class="p">]</span>
            
        <span class="k">for</span> <span class="n">handler</span> <span class="ow">in</span> <span class="n">handlers</span><span class="p">:</span>
            <span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
        
    <span class="k">return</span> <span class="n">LoggerAdapter</span><span class="p">(</span><span class="n">logger</span><span class="p">,</span> <span class="n">options</span><span class="p">,</span> <span class="n">extra</span><span class="p">)</span>

</div>
<div class="viewcode-block" id="get_default_logger"><a class="viewcode-back" href="../index.html#easylogger.get_default_logger">[docs]</a><span class="k">def</span> <span class="nf">get_default_logger</span><span class="p">(</span><span class="n">stream</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Return default logger for this module.</span>
<span class="sd">    </span>
<span class="sd">    :param stream: stream object for default logging handler :class:`logging.StreamHandler`,</span>
<span class="sd">        default value is ``sys.__stdout__``.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">stream</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
        <span class="n">stream</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">__stdout__</span>
    <span class="n">stream_handler</span> <span class="o">=</span> <span class="n">compose_handler</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">stream</span><span class="p">),</span>
                                     <span class="n">Defaults</span><span class="o">.</span><span class="n">GLOBAL_LOGGING_LEVEL</span><span class="p">,</span>
                                     <span class="n">Defaults</span><span class="o">.</span><span class="n">STREAM_MESSAGE_FORMAT</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">get_logger</span><span class="p">(</span><span class="n">handlers</span><span class="o">=</span><span class="p">[</span><span class="n">stream_handler</span><span class="p">])</span>    


<span class="c"># this function copied from inspect module in Python 2.7, the algorithm was</span>
<span class="c"># slightly changed: now it returns list of tuples: </span>
<span class="c"># [(name, value), ...] to retain sequence of attributes.</span>
<span class="c"># Ironically ordered dictionary can be used here, since it was added in 2.7 only.</span></div>
<span class="k">def</span> <span class="nf">getcallargs</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="o">*</span><span class="n">positional</span><span class="p">,</span> <span class="o">**</span><span class="n">named</span><span class="p">):</span> <span class="c">#IGNORE:R0912 #IGNORE:R0914</span>
    <span class="sd">&quot;&quot;&quot;Get the mapping of arguments to values.</span>

<span class="sd">    A dict is returned, with keys the function argument names (including the</span>
<span class="sd">    names of the * and ** arguments, if any), and values the respective bound</span>
<span class="sd">    values from &#39;positional&#39; and &#39;named&#39;.&quot;&quot;&quot;</span>
    <span class="n">args</span><span class="p">,</span> <span class="n">varargs</span><span class="p">,</span> <span class="n">varkw</span><span class="p">,</span> <span class="n">defaults</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">getargspec</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
    <span class="n">f_name</span> <span class="o">=</span> <span class="n">func</span><span class="o">.</span><span class="n">__name__</span>
    
    <span class="n">arg2value_keys</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">arg2value_vals</span> <span class="o">=</span> <span class="p">[]</span>

    <span class="c"># The following closures are basically because of tuple parameter unpacking.</span>
    <span class="n">assigned_tuple_params</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="k">def</span> <span class="nf">assign</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> <span class="c">#IGNORE:C0111</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">arg2value_keys</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
            <span class="n">arg2value_vals</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">assigned_tuple_params</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
            <span class="n">value</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">subarg</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">subvalue</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
                <span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;need more than </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s"> to unpack&#39;</span> <span class="o">%</span>
                                     <span class="p">(</span><span class="n">i</span><span class="p">,</span> <span class="s">&#39;values&#39;</span> <span class="k">if</span> <span class="n">i</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="s">&#39;value&#39;</span><span class="p">))</span>
                <span class="n">assign</span><span class="p">(</span><span class="n">subarg</span><span class="p">,</span> <span class="n">subvalue</span><span class="p">)</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="nb">next</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">StopIteration</span><span class="p">:</span>
                <span class="k">pass</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s">&#39;too many values to unpack&#39;</span><span class="p">)</span>
    <span class="k">def</span> <span class="nf">is_assigned</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span> <span class="c">#IGNORE:C0111</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">arg2value_keys</span>
        <span class="k">return</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">assigned_tuple_params</span>
    <span class="k">if</span> <span class="n">inspect</span><span class="o">.</span><span class="n">ismethod</span><span class="p">(</span><span class="n">func</span><span class="p">)</span> <span class="ow">and</span> <span class="n">func</span><span class="o">.</span><span class="n">im_self</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
        <span class="c"># implicit &#39;self&#39; (or &#39;cls&#39; for classmethods) argument</span>
        <span class="n">positional</span> <span class="o">=</span> <span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">im_self</span><span class="p">,)</span> <span class="o">+</span> <span class="n">positional</span>
    <span class="n">num_pos</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">positional</span><span class="p">)</span>
    <span class="n">num_total</span> <span class="o">=</span> <span class="n">num_pos</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="n">named</span><span class="p">)</span>
    <span class="n">num_args</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
    <span class="n">num_defaults</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">defaults</span><span class="p">)</span> <span class="k">if</span> <span class="n">defaults</span> <span class="k">else</span> <span class="mi">0</span>
    <span class="k">for</span> <span class="n">arg</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">positional</span><span class="p">):</span>
        <span class="n">assign</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">varargs</span><span class="p">:</span>
        <span class="k">if</span> <span class="n">num_pos</span> <span class="o">&gt;</span> <span class="n">num_args</span><span class="p">:</span>
            <span class="n">assign</span><span class="p">(</span><span class="n">varargs</span><span class="p">,</span> <span class="n">positional</span><span class="p">[</span><span class="o">-</span><span class="p">(</span><span class="n">num_pos</span><span class="o">-</span><span class="n">num_args</span><span class="p">):])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">assign</span><span class="p">(</span><span class="n">varargs</span><span class="p">,</span> <span class="p">())</span>
    <span class="k">elif</span> <span class="mi">0</span> <span class="o">&lt;</span> <span class="n">num_args</span> <span class="o">&lt;</span> <span class="n">num_pos</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">() takes </span><span class="si">%s</span><span class="s"> </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s"> (</span><span class="si">%d</span><span class="s"> given)&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">f_name</span><span class="p">,</span> <span class="s">&#39;at most&#39;</span> <span class="k">if</span> <span class="n">defaults</span> <span class="k">else</span> <span class="s">&#39;exactly&#39;</span><span class="p">,</span> <span class="n">num_args</span><span class="p">,</span>
            <span class="s">&#39;arguments&#39;</span> <span class="k">if</span> <span class="n">num_args</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="s">&#39;argument&#39;</span><span class="p">,</span> <span class="n">num_total</span><span class="p">))</span>
    <span class="k">elif</span> <span class="n">num_args</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="n">num_total</span><span class="p">:</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">() takes no arguments (</span><span class="si">%d</span><span class="s"> given)&#39;</span> <span class="o">%</span>
                        <span class="p">(</span><span class="n">f_name</span><span class="p">,</span> <span class="n">num_total</span><span class="p">))</span>
    <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span><span class="p">:</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="nb">str</span><span class="p">)</span> <span class="ow">and</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">named</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">is_assigned</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">() got multiple values for keyword &quot;</span>
                                <span class="s">&quot;argument &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">f_name</span><span class="p">,</span> <span class="n">arg</span><span class="p">))</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">assign</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">named</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="n">arg</span><span class="p">))</span>
    <span class="k">if</span> <span class="n">defaults</span><span class="p">:</span>    <span class="c"># fill in any missing values with the defaults</span>
        <span class="k">for</span> <span class="n">arg</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="nb">zip</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="o">-</span><span class="n">num_defaults</span><span class="p">:],</span> <span class="n">defaults</span><span class="p">):</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">is_assigned</span><span class="p">(</span><span class="n">arg</span><span class="p">):</span>
                <span class="n">assign</span><span class="p">(</span><span class="n">arg</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">varkw</span><span class="p">:</span>
        <span class="n">assign</span><span class="p">(</span><span class="n">varkw</span><span class="p">,</span> <span class="n">named</span><span class="p">)</span>
    <span class="k">elif</span> <span class="n">named</span><span class="p">:</span>
        <span class="n">unexpected</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="nb">iter</span><span class="p">(</span><span class="n">named</span><span class="p">))</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">unexpected</span><span class="p">,</span> <span class="nb">unicode</span><span class="p">):</span>
            <span class="n">unexpected</span> <span class="o">=</span> <span class="n">unexpected</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">getdefaultencoding</span><span class="p">(),</span> <span class="s">&#39;replace&#39;</span><span class="p">)</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">() got an unexpected keyword argument &#39;</span><span class="si">%s</span><span class="s">&#39;&quot;</span> <span class="o">%</span>
                        <span class="p">(</span><span class="n">f_name</span><span class="p">,</span> <span class="n">unexpected</span><span class="p">))</span>
    <span class="n">unassigned</span> <span class="o">=</span> <span class="n">num_args</span> <span class="o">-</span> <span class="nb">len</span><span class="p">([</span><span class="n">arg</span> <span class="k">for</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">args</span> <span class="k">if</span> <span class="n">is_assigned</span><span class="p">(</span><span class="n">arg</span><span class="p">)])</span>
    <span class="k">if</span> <span class="n">unassigned</span><span class="p">:</span>
        <span class="n">num_required</span> <span class="o">=</span> <span class="n">num_args</span> <span class="o">-</span> <span class="n">num_defaults</span>
        <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&#39;</span><span class="si">%s</span><span class="s">() takes </span><span class="si">%s</span><span class="s"> </span><span class="si">%d</span><span class="s"> </span><span class="si">%s</span><span class="s"> (</span><span class="si">%d</span><span class="s"> given)&#39;</span> <span class="o">%</span> <span class="p">(</span>
            <span class="n">f_name</span><span class="p">,</span> <span class="s">&#39;at least&#39;</span> <span class="k">if</span> <span class="n">defaults</span> <span class="k">else</span> <span class="s">&#39;exactly&#39;</span><span class="p">,</span> <span class="n">num_required</span><span class="p">,</span>
            <span class="s">&#39;arguments&#39;</span> <span class="k">if</span> <span class="n">num_required</span> <span class="o">&gt;</span> <span class="mi">1</span> <span class="k">else</span> <span class="s">&#39;argument&#39;</span><span class="p">,</span> <span class="n">num_total</span><span class="p">))</span>
    <span class="k">return</span> <span class="nb">zip</span><span class="p">(</span><span class="n">arg2value_keys</span><span class="p">,</span> <span class="n">arg2value_vals</span><span class="p">)</span>


<span class="k">class</span> <span class="nc">_LoggerDecoratorHelper</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> <span class="c">#IGNORE:R0903</span>
    <span class="sd">&quot;&quot;&quot;Logger helper.&quot;&quot;&quot;</span>
    
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">logger</span><span class="p">,</span> <span class="n">level</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">logger</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">level</span> <span class="o">=</span> <span class="n">level</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">options</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="bp">None</span>
    
    <span class="k">def</span> <span class="nf">_get_arguments</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return arguments and their values provided for function &#39;func&#39;.</span>
<span class="sd">        This information should be cached for current session. Probably</span>
<span class="sd">        cache should be used for every equal triple (func, args, kwargs).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="n">getcallargs</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span>
    
    <span class="k">def</span> <span class="nf">_parameters_to_string</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span> <span class="c">#IGNORE:R0201</span>
        <span class="sd">&quot;&quot;&quot;Format provided arguments to output them as Python code.&quot;&quot;&quot;</span>
        
        <span class="n">items</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_arguments</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
        <span class="n">parent</span> <span class="o">=</span> <span class="nb">dict</span><span class="p">(</span><span class="n">items</span><span class="p">)</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s">&quot;self&quot;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>
        
        <span class="n">_</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">items</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">k</span> <span class="o">!=</span> <span class="s">&quot;self&quot;</span><span class="p">:</span>
                <span class="n">_</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s">&quot;{0}={1}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="s">&quot;&#39;{0}&#39;&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">v</span><span class="p">)</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">v</span><span class="p">,</span> <span class="nb">basestring</span><span class="p">)</span> <span class="k">else</span> <span class="n">v</span><span class="p">))</span>        
        
        <span class="k">if</span> <span class="n">parent</span><span class="p">:</span>
            <span class="c"># it&#39;s a method</span>
            
            <span class="c"># support for classmethods</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">inspect</span><span class="o">.</span><span class="n">isclass</span><span class="p">(</span><span class="n">parent</span><span class="p">):</span>
                <span class="n">parent</span> <span class="o">=</span> <span class="n">parent</span><span class="o">.</span><span class="n">__class__</span>
                
            <span class="n">func_info</span> <span class="o">=</span> <span class="s">&quot;method {0}.{1}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">parent</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
                                                <span class="n">func</span><span class="o">.</span><span class="n">__name__</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="c"># it&#39;s a function</span>
            <span class="n">func_info</span> <span class="o">=</span> <span class="s">&quot;function {0}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">func</span><span class="o">.</span><span class="n">__name__</span><span class="p">)</span>
        
        <span class="k">return</span> <span class="s">&quot;Executing {0}({1}).&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">func_info</span><span class="p">,</span> <span class="s">&quot;, &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">_</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">_doc_processing</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Log doc stings.&quot;&quot;&quot;</span>
        <span class="n">doc</span> <span class="o">=</span> <span class="n">inspect</span><span class="o">.</span><span class="n">getdoc</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">doc</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="c"># formatting</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">doc</span> <span class="o">=</span> <span class="n">doc</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="o">**</span><span class="nb">dict</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_get_arguments</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)))</span>
            <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
                <span class="k">pass</span>
            
            <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="n">doc</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">):</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">doc_processing_prefix</span><span class="p">:</span>
                    <span class="k">if</span> <span class="n">_</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">doc_processing_prefix</span><span class="p">):</span>
                        <span class="n">_</span> <span class="o">=</span> <span class="n">_</span><span class="p">[</span><span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">doc_processing_prefix</span><span class="p">):]</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="k">continue</span>
                    
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">doc_processing_level</span><span class="p">,</span> <span class="n">_</span><span class="p">)</span>        
        
    <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">func</span><span class="p">):</span>
        
        <span class="nd">@functools.wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
        <span class="k">def</span> <span class="nf">wrapper</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
            <span class="sd">&quot;&quot;&quot; Simple wrapper.&quot;&quot;&quot;</span>
            
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">enable_decorator_mode</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">level</span><span class="p">,</span>
                                <span class="bp">self</span><span class="o">.</span><span class="n">_parameters_to_string</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">))</span>
                
                <span class="c"># log doc-strings</span>
                <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">enable_doc_processing</span><span class="p">:</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">_doc_processing</span><span class="p">(</span><span class="n">func</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
            
                <span class="c"># empty cached values:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="bp">None</span>
            
            <span class="c"># execute the function</span>
            <span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        
        <span class="k">return</span> <span class="n">wrapper</span>


<span class="k">class</span> <span class="nc">_LoggerStreamHelper</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Imitation of stream object. </span>
<span class="sd">    </span>
<span class="sd">    sys.stdout (sys.stderr) can be replaced with this imitation.</span>
<span class="sd">    </span>
<span class="sd">    Supported methods: </span>
<span class="sd">        write, writelines, close, and flush</span>
<span class="sd">    &quot;&quot;&quot;</span>
    
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">logger</span><span class="p">,</span> <span class="n">level</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">logger</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">level</span> <span class="o">=</span> <span class="n">level</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">closed</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="p">[]</span>
    
    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write provided string to a stream.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">closed</span><span class="p">:</span>
            
            <span class="k">if</span> <span class="ow">not</span> <span class="n">msg</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">):</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">msg</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">))</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">writelines</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">lines</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Write a sequence of strings to the file.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">flush</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Flush cached messages to logger.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">level</span><span class="p">,</span> <span class="s">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_cache</span><span class="p">))</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_cache</span> <span class="o">=</span> <span class="p">[]</span>
    
    <span class="k">def</span> <span class="nf">close</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Close current stream.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">closed</span> <span class="o">=</span> <span class="bp">True</span>
    

<span class="c"># Copied from logging module and updated.</span>
<div class="viewcode-block" id="LoggerAdapter"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter">[docs]</a><span class="k">class</span> <span class="nc">LoggerAdapter</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    An adapter for loggers which makes it easier to specify contextual</span>
<span class="sd">    information in logging output.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">logger</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">extra</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize the adapter with a logger and a dict-like object which</span>
<span class="sd">        provides contextual information. This constructor signature allows</span>
<span class="sd">        easy stacking of LoggerAdapters, if so desired.</span>

<span class="sd">        You can effectively pass keyword arguments as shown in the</span>
<span class="sd">        following example:</span>

<span class="sd">        adapter = LoggerAdapter(someLogger, extra=dict(p1=v1, p2=&quot;v2&quot;))</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span> <span class="o">=</span> <span class="n">logger</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">extra</span> <span class="o">=</span> <span class="n">extra</span> <span class="ow">or</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">options</span> <span class="ow">or</span> <span class="n">LoggingOptions</span><span class="p">()</span>

<div class="viewcode-block" id="LoggerAdapter.process_message"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.process_message">[docs]</a>    <span class="k">def</span> <span class="nf">process_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Process the logging message and keyword arguments passed in to</span>
<span class="sd">        a logging call to insert contextual information. You can either</span>
<span class="sd">        manipulate the message itself, args or keyword args. Return</span>
<span class="sd">        the message, args and kwargs modified (or not) to suit your needs.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">extra</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&quot;extra&quot;</span><span class="p">,</span> <span class="p">{}))</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s">&quot;extra&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">extra</span>
        
        <span class="c"># processing with &#39;indent&#39; options</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">indent</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">indent</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
                <span class="n">indent</span> <span class="o">=</span> <span class="s">&quot; &quot;</span> <span class="o">*</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">indent</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">indent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">indent</span>
            
            <span class="n">msg</span> <span class="o">=</span> <span class="s">&quot;{0}{1}&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">indent</span><span class="p">,</span> <span class="n">msg</span><span class="p">)</span>
        
        <span class="c"># processing with new message system</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">enable_new_style</span><span class="p">:</span>
            <span class="c"># TODO: support new formatting style</span>
            <span class="n">args</span> <span class="o">=</span> <span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="p">)</span> <span class="o">+</span> <span class="n">args</span>
            <span class="n">msg</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="o">.</span><span class="n">new_style_delimiter</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">&quot;</span><span class="si">%s</span><span class="s">&quot;</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="n">args</span><span class="p">])</span>
        
        <span class="k">return</span> <span class="n">msg</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.debug"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.debug">[docs]</a>    <span class="k">def</span> <span class="nf">debug</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate a debug call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">DEBUG</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.info"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.info">[docs]</a>    <span class="k">def</span> <span class="nf">info</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate an info call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">INFO</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.warning"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.warning">[docs]</a>    <span class="k">def</span> <span class="nf">warning</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate a warning call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">WARNING</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.error"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.error">[docs]</a>    <span class="k">def</span> <span class="nf">error</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate an error call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">ERROR</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.exception"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.exception">[docs]</a>    <span class="k">def</span> <span class="nf">exception</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate an exception call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s">&quot;exc_info&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="mi">1</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">ERROR</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.critical"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.critical">[docs]</a>    <span class="k">def</span> <span class="nf">critical</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate a critical call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">CRITICAL</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.log"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.log">[docs]</a>    <span class="k">def</span> <span class="nf">log</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">level</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delegate a log call to the underlying logger, after adding</span>
<span class="sd">        contextual information from this adapter instance.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c"># we need to detect if log&#39;s method used as decorators, if so msg </span>
        <span class="c"># should be a function (or method) and args, kwargs must be empty.</span>
        <span class="k">if</span> <span class="p">((</span><span class="n">inspect</span><span class="o">.</span><span class="n">ismethod</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span> <span class="ow">or</span> <span class="n">inspect</span><span class="o">.</span><span class="n">isfunction</span><span class="p">(</span><span class="n">msg</span><span class="p">))</span> <span class="ow">and</span> 
             <span class="ow">not</span> <span class="n">args</span> <span class="ow">and</span> 
             <span class="p">(</span><span class="ow">not</span> <span class="n">kwargs</span> <span class="ow">or</span> <span class="p">(</span><span class="s">&quot;exc_info&quot;</span> <span class="ow">in</span> <span class="n">kwargs</span> <span class="ow">and</span> <span class="nb">len</span><span class="p">(</span><span class="n">kwargs</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span><span class="o">==</span><span class="mi">1</span><span class="p">))):</span>
            <span class="c"># ok, we are in &#39;decorator&#39; mode</span>
            <span class="k">return</span> <span class="n">_LoggerDecoratorHelper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">level</span><span class="p">)(</span><span class="n">msg</span><span class="p">)</span>
                
        <span class="n">msg</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">process_message</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="n">level</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</div>
<div class="viewcode-block" id="LoggerAdapter.append_handlers"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.append_handlers">[docs]</a>    <span class="k">def</span> <span class="nf">append_handlers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">handlers</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Append provided handlers to the list of existed ones.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">handler</span> <span class="ow">in</span> <span class="n">handlers</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="LoggerAdapter.replace_handlers"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.replace_handlers">[docs]</a>    <span class="k">def</span> <span class="nf">replace_handlers</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">handlers</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Replace current list of handlers with the provided ones.&quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">handler</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">handlers</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">removeHandler</span><span class="p">(</span><span class="n">handler</span><span class="p">)</span>
            
        <span class="bp">self</span><span class="o">.</span><span class="n">append_handlers</span><span class="p">(</span><span class="o">*</span><span class="n">handlers</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="LoggerAdapter.set_level"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.set_level">[docs]</a>    <span class="k">def</span> <span class="nf">set_level</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">level</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set logging level for current logger only.&quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="LoggerAdapter.get_level"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.get_level">[docs]</a>    <span class="k">def</span> <span class="nf">get_level</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return current logger&#39;s level.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">level</span>
    </div>
    <span class="n">level</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">get_level</span><span class="p">,</span> <span class="n">set_level</span><span class="p">)</span>
    
<div class="viewcode-block" id="LoggerAdapter.set_effective_level"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.set_effective_level">[docs]</a>    <span class="k">def</span> <span class="nf">set_effective_level</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">level</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set effective level: set the same logging level for current logger</span>
<span class="sd">        and for all its handlers.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">for</span> <span class="n">handler</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">handlers</span><span class="p">:</span>
            <span class="n">handler</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
        
        <span class="bp">self</span><span class="o">.</span><span class="n">set_level</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
        </div>
<div class="viewcode-block" id="LoggerAdapter.get_effective_level"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.get_effective_level">[docs]</a>    <span class="k">def</span> <span class="nf">get_effective_level</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return effective logging level, any message produced with this level</span>
<span class="sd">        will be logged by all attached handlers.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">max</span><span class="p">([</span><span class="n">_</span><span class="o">.</span><span class="n">level</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">handlers</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">logger</span><span class="o">.</span><span class="n">level</span><span class="p">])</span>
</div>
    <span class="n">effective_level</span> <span class="o">=</span> <span class="nb">property</span><span class="p">(</span><span class="n">get_effective_level</span><span class="p">,</span> <span class="n">set_effective_level</span><span class="p">)</span>

<div class="viewcode-block" id="LoggerAdapter.set_options"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.set_options">[docs]</a>    <span class="k">def</span> <span class="nf">set_options</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Set logging options, see :class:`LoggingOptions` class above.</span>
<span class="sd">        </span>
<span class="sd">        :param args: here can be only one positional argument: instance of</span>
<span class="sd">            LoggingOptions object, if it&#39;s provided, keyword arguments will</span>
<span class="sd">            be ignored and current logging options will be replaced with</span>
<span class="sd">            provided ones;</span>
<span class="sd">        :param kwargs: any existing options can be provided (see available in</span>
<span class="sd">            :class:`LoggingOptions` class);</span>
<span class="sd">        &quot;&quot;&quot;</span>
        
        <span class="k">if</span> <span class="n">args</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">args</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">1</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">RuntimeError</span><span class="p">(</span><span class="s">&quot;Only one positional argument is allowed.&quot;</span><span class="p">)</span>
            
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">LoggingOptions</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span><span class="s">&quot;Provided argument must be an instance of&quot;</span>
                                <span class="s">&quot; LoggingOptions object.&quot;</span><span class="p">)</span>
            
            <span class="c"># The interesting moment to notice here. If we perform a direct</span>
            <span class="c"># options assignment, we broke the link between self.options and</span>
            <span class="c"># self.logger.options passed to _LoggerDecoratorHelper, when</span>
            <span class="c"># decorator was created, thus any further call to log.set_options</span>
            <span class="c"># method will not change already created decorators behavior.</span>
            <span class="c"># So we need to set new properties one by one using &#39;setattr&#39;.</span>
            
            <span class="c"># self.options = args[0]</span>
            <span class="n">kwargs</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">__dict__</span>
        
        <span class="c"># process keyword arguments</span>
        <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">iteritems</span><span class="p">():</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">,</span> <span class="n">key</span><span class="p">):</span>
                <span class="k">raise</span> <span class="ne">AttributeError</span><span class="p">(</span><span class="s">&quot;Unsupported option is passed: {0}&quot;</span>
                                     <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">key</span><span class="p">))</span>
            
            <span class="nb">setattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">options</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
    </div>
<div class="viewcode-block" id="LoggerAdapter.get_stream"><a class="viewcode-back" href="../index.html#easylogger.LoggerAdapter.get_stream">[docs]</a>    <span class="k">def</span> <span class="nf">get_stream</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">level</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return stream imitation object, which can replace stdout and</span>
<span class="sd">        stderr streams.</span>
<span class="sd">        </span>
<span class="sd">        :param level: logging level, messages will be logged with,</span>
<span class="sd">            usually :const:`STDOUT` or :const:`STDERR`;</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="n">_LoggerStreamHelper</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">level</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">level</span><span class="p">)</span>
        </div>
    <span class="k">def</span> <span class="nf">__call__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Calling log instance should act as usual &#39;info&#39; or &#39;debug&#39; methods.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">log</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">level</span><span class="p">,</span> <span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>


<span class="c"># Default logger object, can be used right after it is imported. </span></div>
<span class="n">log</span> <span class="o">=</span> <span class="n">get_default_logger</span><span class="p">()</span>


<div class="viewcode-block" id="info"><a class="viewcode-back" href="../index.html#easylogger.info">[docs]</a><span class="k">def</span> <span class="nf">info</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Log a message with severity ``INFO`` on the root logger.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">log</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    </div>
<div class="viewcode-block" id="debug"><a class="viewcode-back" href="../index.html#easylogger.debug">[docs]</a><span class="k">def</span> <span class="nf">debug</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Log a message with severity ``DEBUG`` on the root logger.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">log</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    
    </div>
<div class="viewcode-block" id="warning"><a class="viewcode-back" href="../index.html#easylogger.warning">[docs]</a><span class="k">def</span> <span class="nf">warning</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Log a message with severity ``WARNING`` on the root logger.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">log</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    </div>
<span class="n">warn</span> <span class="o">=</span> <span class="n">warning</span> 
 
<div class="viewcode-block" id="error"><a class="viewcode-back" href="../index.html#easylogger.error">[docs]</a><span class="k">def</span> <span class="nf">error</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Log a message with severity ``ERROR`` on the root logger.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">log</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    
    </div>
<div class="viewcode-block" id="exception"><a class="viewcode-back" href="../index.html#easylogger.exception">[docs]</a><span class="k">def</span> <span class="nf">exception</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Log a message with severity ``ERROR`` on the root logger.&quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">log</span><span class="o">.</span><span class="n">exception</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
    
    </div>
<div class="viewcode-block" id="critical"><a class="viewcode-back" href="../index.html#easylogger.critical">[docs]</a><span class="k">def</span> <span class="nf">critical</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Log a message with severity ``CRITICAL`` on the root logger.&quot;&quot;&quot;</span>    
    <span class="k">return</span> <span class="n">log</span><span class="o">.</span><span class="n">critical</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
</pre></div></div>

          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" size="18" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li><a href="../index.html">easylogger v0.1 documentation</a> &raquo;</li>
          <li><a href="index.html" >Module code</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
        &copy; Copyright 2011, Oleg Churkin.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>
  </body>
</html>